use std::io;
use std::io::Cursor;

// claxon
pub fn run_claxon(data: &[u8]) {
    let cursor = Cursor::new(data);
    // println!("{}", data.len());
    let mut reader = match claxon::FlacReader::new(cursor) {
        Ok(r) => r,
        Err(..) => return,
    };

    for sample in reader.samples() {
        match sample {
            Ok(..) => { }
            Err(..) => return,
        }
    }
}

// simd_json
use simd_json;
pub fn run_simd_json(data: &[u8]) {
    let mut data1 = data.clone().to_vec();
    if let Ok(ref jo) = simd_json::to_owned_value(&mut data1) {
        jo.to_string();
        // println!("{}", );
    }
}

// libflate
use libflate::gzip;
pub fn run_libflate_gzip(data: &[u8]) {
    if let Ok(mut decoder) = gzip::MultiDecoder::new(data) {
        let mut buf = Vec::with_capacity(data.len());
        io::copy(&mut decoder, &mut buf);
    }
   

    let mut ds = String::from("");
    let data2 = ds.as_bytes();
    //let mut decoder = gzip::MultiDecoder::new(data);
    //let mut decoder = gzip::MultiDecoder::new(data2.as_bytes());

    // let mut decoder = gzip::MultiDecoder::new(data);
    // if let Ok(mut decoder2) = gzip::MultiDecoder::new(data2) {
    //     let mut buf2 = Vec::with_capacity(data2.len());
    //     io::copy(&mut decoder2, &mut buf2);
    // }
}

// safe_transmute_rs
use safe_transmute::guarded_transmute_vec_permissive;
pub fn run_safe_transmute(data: &[u8]) {
    //transmute_many_pedantic::<u8>(transmute_to_bytes::<u8>(data))
    let dv = data.to_vec();

    let mut v = vec![1];
    v.push(0);
    v.push(1);
    v.push(2); // now capacity is 4
    v.pop();
    v.resize(100, 0);
    v.pop();
    v.pop();
    v.pop();
    println!("data size: {} cap: {}", v.len(), v.capacity());
    unsafe {guarded_transmute_vec_permissive::<u8>(v);}
   
    //unsafe {guarded_transmute_vec_permissive::<u8>(dv);}
}

// image
use image;
pub fn run_test_image(data: &[u8]) {
    let _ = image::load_from_memory_with_format(data, image::ImageFormat::HDR);
}